local hx__zhiheng_mou = fk.CreateSkill {
  name = "hx__zhiheng_mou",
}

hx__zhiheng_mou:addEffect("active", {
  anim_type = "drawcard",
  min_card_num = 1,
  target_num = 0,
  prompt = "#hx__zhiheng_mou-active",
  can_use = function(self, player)
    return player:usedSkillTimes(hx__zhiheng_mou.name, Player.HistoryPhase) < 1 + player:getMark("@hx__tongye_mou_addEffect-turn")
  end,
  card_filter = function(self, player, to_select, selected)
    return not player:prohibitDiscard(to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local hand = player:getCardIds(Player.Hand)
    local more = #hand > 0
    for _, id in ipairs(hand) do
      if not table.contains(effect.cards, id) then
        more = false
        break
      end
    end
    room:throwCard(effect.cards, hx__zhiheng_mou.name, player, player)
    for _, id in ipairs(effect.cards) do
      if Fk:getCardById(id).suit ~= Card.NoSuit then
        room:addTableMarkIfNeed(player, "@hx__zhiheng_mou_suit", Fk:getCardById(id):getSuitString(true))
      end
      room:addTableMarkIfNeed(player, "@hx__zhiheng_mou_type", Fk:getCardById(id):getTypeString())
    end
    if #player:getTableMark("@hx__zhiheng_mou_suit") >= 4 then
      local choice = room:askToChoice(player,{
        choices = {"Cancel", "获得"},
        skill_name = hx__zhiheng_mou.name,
        cancelable = true,
        prompt = "你制衡的花色达到了四种，是否获得1个“业”标记？（你至多拥有两个“业”标记）"
      })
      if choice == "获得" then
        room:setPlayerMark(player, "@hx__zhiheng_mou_suit", 0)
        if player:getMark("@hx__zhiheng_mou_ye") < 2 then
          room:addPlayerMark(player, "@hx__zhiheng_mou_ye", 1)
        end
      end
    end
    if #player:getTableMark("@hx__zhiheng_mou_type") >= 3 then
      local choice = room:askToChoice(player,{
        choices = {"Cancel", "获得"},
        skill_name = hx__zhiheng_mou.name,
        cancelable = true,
        prompt = "你制衡的类型达到了三种，是否获得1个“业”标记？（你至多拥有两个“业”标记）"
      })
      if choice == "获得" then
        room:setPlayerMark(player, "@hx__zhiheng_mou_type", 0)
        if player:getMark("@hx__zhiheng_mou_ye") < 2 then
          room:addPlayerMark(player, "@hx__zhiheng_mou_ye", 1)
        end
      end
    end
    if not player.dead then
      room:drawCards(player, #effect.cards + (more and 1 or 0), hx__zhiheng_mou.name)
    end
  end
})

return hx__zhiheng_mou
